﻿using JuCheap.Core.Infrastructure;
using JuCheap.Core.Interfaces;
using Microsoft.AspNetCore.Hosting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace JuCheap.Core.Web.Services
{
    public class FileLocationProvider : IFileLocationProvider
    {
        private readonly IHostingEnvironment _hostingEnvironment;

        public FileLocationProvider(IHostingEnvironment env)
        {
            _hostingEnvironment = env;
        }
        public string GetAbsoluteLocation(string path)
        {
            var fileName = Path.Combine(_hostingEnvironment.WebRootPath, "upload", path);
            if (!File.Exists(fileName))
            {
                throw new DomainException($"file: {path} not found.");
            }
            return fileName;
        }
    }
}
